package terra.twl.window;

import terra.model.Experience;
import terra.model.Player;
import terra.slick.GameState;
import de.matthiasmann.twl.ProgressBar;
import de.matthiasmann.twl.Widget;

public class HpBar extends Widget {
	
	ProgressBar hp,breath,exp;
	
	public HpBar(){
        exp = new ProgressBar();
        exp.setTheme("exp");
        exp.setText("Exp ");
        exp.setValue(1.0f);
        breath = new ProgressBar();
        breath.setTheme("breath");
        breath.setValue(1.0f);
        breath.setText("Breath ");
        hp = new ProgressBar();
        hp.setTheme("health");
        hp.setValue(1.0f);
        hp.setText("Health ");
        
		add(hp);
		add(breath);
		add(exp);
	}

	@Override
	protected void layout() {
		hp.setSize(getInnerWidth(), 12);
		breath.setSize(getInnerWidth(), 12);
		exp.setSize(getInnerWidth(), 12);
		
		hp.setPosition(getInnerX(), getInnerY());
		breath.setPosition(getInnerX(), getInnerY()+20);
		exp.setPosition(getInnerX(), getInnerY()+40);
	}

    public void update(){
    	Player p = GameState.getInstance().player;
    	if (p == null)
    		return;
		float hpPercent = p.getMaxHp()/100f;
		hp.setValue((p.getCurrentHp()/hpPercent)/100);
		hp.setText("Health "+ p.getCurrentHp() + " / " + p.getMaxHp());
		float breathPercent = p.getMaxBreath()/100f;
		//System.out.println("asdasd "+ breathPercent);
		breath.setValue((p.getCurrentBreath()/breathPercent)/100f);
		breath.setText("Breath "+ p.getCurrentBreath() + " / " + p.getMaxBreath());
		float expPercent = (Experience.LEVEL[p.getLevel()+1]-Experience.LEVEL[p.getLevel()])/100;
		exp.setValue((p.getExp()/expPercent)/100);
		exp.setText("Exp "+ p.getExp() + " / " + (Experience.LEVEL[p.getLevel()+1]-Experience.LEVEL[p.getLevel()]));
    }
}
